package com.bee.web.vo;

/**
 * 按步骤set此对象
 * 第1.第几页page和每页几条是前台过来的,没有就默认;
 * 第2.数据data;
 * 第3.有几条count;
 * 第4.总条数totalCount:计算共有几页totalPage,上一页是第几页upPage,下一页是第几页downPage
 *
 * @author liuzy
 * @version 2015年6月13日
 */
public class BaseVo {
    private String status = "success";
    private String message = "请求成功";
    /**
     * 数据
     */
    private Object data;
    /**
     * 有几条
     */
    private int count;
    /**
     * 第几页
     */
    private int page = 1;
    /**
     * 每页几条
     */
    private int rows = 10;
    /**
     * 共有几条
     */
    private int totalCount;
    /**
     * 共有几页
     */
    private int totalPage;
    /**
     * 上一页是第几页
     */
    private int upPage;
    /**
     * 下一页是第几页
     */
    private int downPage;

    public BaseVo() {
    }
    
    public BaseVo(int page, int rows) {
    	this.page = page;
    	this.rows = rows;
    }

    public BaseVo(String status, String message) {
        this.status = status;
        this.message = message;
    }

    public BaseVo(String message) {
        this.status = "fail";
        this.message = message;
    }

    public BaseVo(Object data) {
        this.data = data;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        if (page <= 0) {
            this.page = 1;
        } else {
            this.page = page;
        }
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        if (rows <= 0) {
            this.rows = 10;
        } else {
            this.rows = rows;
        }
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        //计算共有几页totalPage,上一页是第几页upPage,下一页是第几页downPage
        if (totalCount > 0) {
            this.totalPage = totalCount <= rows ? 1 : (totalCount % rows == 0 ? totalCount / rows : totalCount / rows + 1);
            this.upPage = page == 1 ? 1 : page + 1;
            this.downPage = totalPage == page ? page : page + 1;
        }
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getUpPage() {
        return upPage;
    }

    public void setUpPage(int upPage) {
        this.upPage = upPage;
    }

    public int getDownPage() {
        return downPage;
    }

    public void setDownPage(int downPage) {
        this.downPage = downPage;
    }
}
